<template><div><h2 id="ector" tabindex="-1"><a class="header-anchor" href="#ector"><span>ector</span></a></h2>
<p>可变长度的数组</p>
<div class="language-c++ line-numbers-mode has-collapsed-lines collapsed" data-highlighter="shiki" data-ext="c++" style="--vp-collapsed-lines:15;background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic">// 声明</span></span>
<span class="line"><span style="color:#ABB2BF">vector</span><span style="color:#C678DD">&#x3C;int></span><span style="color:#ABB2BF"> a;</span></span>
<span class="line"><span style="color:#ABB2BF">vector</span><span style="color:#C678DD">&#x3C;double></span><span style="color:#ABB2BF"> b;</span></span>
<span class="line"><span style="color:#E5C07B">vector</span><span style="color:#ABB2BF">&#x3C;</span><span style="color:#C678DD">int</span><span style="color:#ABB2BF">> </span><span style="color:#61AFEF">a</span><span style="color:#ABB2BF">(</span><span style="color:#D19A66">5</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">);</span><span style="color:#7F848E;font-style:italic"> // 初始化5个1元素</span></span>
<span class="line"><span style="color:#ABB2BF">vector</span><span style="color:#C678DD">&#x3C;int></span><span style="color:#ABB2BF"> a{</span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">2</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">3</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">4</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">5</span><span style="color:#ABB2BF">};</span><span style="color:#7F848E;font-style:italic"> // 初始化为1,2,3,4,5</span></span>
<span class="line"><span style="color:#ABB2BF">vector</span><span style="color:#C678DD">&#x3C;</span><span style="color:#ABB2BF">vector</span><span style="color:#C678DD">&#x3C;int>></span><span style="color:#ABB2BF"> c;</span><span style="color:#7F848E;font-style:italic"> // 二维数组声明</span></span>
<span class="line"><span style="color:#ABB2BF">{</span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">2</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">3</span><span style="color:#ABB2BF">,</span><span style="color:#D19A66">4</span><span style="color:#ABB2BF">};</span><span style="color:#7F848E;font-style:italic"> // 无名vector;</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 插入数据</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">push_back</span><span style="color:#ABB2BF">(</span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">);</span></span>
<span class="line"><span style="color:#ABB2BF">cin </span><span style="color:#C678DD">>></span><span style="color:#E5C07B"> a</span><span style="color:#ABB2BF">[</span><span style="color:#D19A66">0</span><span style="color:#ABB2BF">];</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 查找数据的方法</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">size</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 查看数组实际的元素个数</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">begin</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 返回数组首元素的地址</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">end</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 返回数组尾元素的地址</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">empty</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 判断数组是否为空</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 删除数据的方法</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">pop_back</span><span style="color:#ABB2BF">()；</span><span style="color:#7F848E;font-style:italic"> // 删除最后一位</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 修改数据的方法</span></span>
<span class="line"><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">[</span><span style="color:#D19A66">0</span><span style="color:#ABB2BF">] </span><span style="color:#C678DD">=</span><span style="color:#D19A66"> 1</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 常用函数</span></span>
<span class="line"><span style="color:#61AFEF">sort</span><span style="color:#ABB2BF">(</span><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">begin</span><span style="color:#ABB2BF">(),</span><span style="color:#E5C07B">a</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">end</span><span style="color:#ABB2BF">());</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div><div class="collapsed-lines"></div></div><h2 id="stack" tabindex="-1"><a class="header-anchor" href="#stack"><span>stack</span></a></h2>
<p>栈</p>
<div class="language-c++ line-numbers-mode" data-highlighter="shiki" data-ext="c++" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic">// 声明</span></span>
<span class="line"><span style="color:#ABB2BF">stack</span><span style="color:#C678DD">&#x3C;int></span><span style="color:#ABB2BF"> s;</span></span>
<span class="line"><span style="color:#ABB2BF">stack</span><span style="color:#C678DD">&#x3C;</span><span style="color:#ABB2BF">string</span><span style="color:#C678DD">></span><span style="color:#ABB2BF"> s;</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">// 增删改查</span></span>
<span class="line"><span style="color:#E5C07B">s</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">push</span><span style="color:#ABB2BF">(</span><span style="color:#D19A66">1</span><span style="color:#ABB2BF">);</span><span style="color:#7F848E;font-style:italic"> // 压入一个元素</span></span>
<span class="line"><span style="color:#E5C07B">s</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">pop</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 删除栈顶元素</span></span>
<span class="line"><span style="color:#E5C07B">s</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">top</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 返回栈顶元素</span></span>
<span class="line"><span style="color:#E5C07B">s</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">empty</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 判断栈是否为空</span></span>
<span class="line"><span style="color:#E5C07B">s</span><span style="color:#ABB2BF">.</span><span style="color:#61AFEF">size</span><span style="color:#ABB2BF">();</span><span style="color:#7F848E;font-style:italic"> // 判断栈里面的元素个数</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div></template>


